<?php

namespace App\Handler\Admin\Structure\Certificate;

if (!defined('IN_PX'))
    exit;

use App\Handler\Admin\AbstractCommon;
use Phoenix\Support\MsgHelper;
use App\Tools\Html;

/**
 * 添加
 *
 */
class Add extends AbstractCommon {

    public function processRequest(Array & $context) {
        $this->_pushSetting();
        $this->_processingParameters();

        //$this->db->debug();
        $_POST['category_id'] = intval($_POST['category_id']);
        $_POST['title'] = Html::getLenStr(trim($_POST['title']), 50);
        $_POST['is_status'] = intval($_POST['is_status']);
        $_POST['add_date'] =  $_POST['release_date'] = time();

//        $this->db->debug();
        $_identity = $this->db->table('`#@__@certificate`')
            ->row(array(
                '`category_id`' => '?',
                '`title`' => '?',
                '`is_status`' => '?',
                '`cover`' => '?',
                '`sort`' => '?',
                '`add_date`' => '?',
                '`release_date`' => '?',
                '`language`' => '?'
            ))
            ->bind($_POST)
            ->save();


        if ($_POST['cover'] != '') {
            $this->_createImg('cover');
        }

        echo(MsgHelper::json($_identity ? 'SUCCESS' : 'DB_ERROR'));
    }
}
